import logger from './logger';
import router from '@ohos.router';
import globalData from './globalData';
import { routerParam } from '../models/routerParam';

class page {
  navigate(view: string): void {
    try {
      router.pushUrl({
        url: `pages/${view}`
      });
    } catch (e) {
      logger.error(e);
    }
  }

  navigateWith(view: string, param: routerParam): void {
    try {
      router.pushUrl({
        url: `pages/${view}`,
        params: param
      });
    } catch (e) {
      logger.error(e);
    }
  }

  navigateBack(): void {
    try {
      router.back();
      router.clear();
    } catch (e) {
      logger.error(e);
    }
  }

  shutdown(): void {
    try {
      globalData.abilityContext?.terminateSelf();
      globalData.abilityDetailContext?.terminateSelf();
    } catch (e) {
      logger.error(e);
    }
  }
}
export default new page();